package com.cm367.teamc.session;

import java.util.Locale;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class Language {

	String lang = "en";
	private Locale locale = new Locale(lang);
	
	public String getLang() {
		return lang;
	}

	public void setLang(String lang) {
		this.lang = lang;
	}

	public void setLocale(Locale locale) {
		this.locale = locale;
	}

	public Locale getLocale() {
		return locale;
	}
	public String changeLang() {
		locale = new Locale(lang);
		FacesContext.getCurrentInstance().getViewRoot()
				.setLocale(locale);
		return null;
	}
	
	public String changeEN() {
		FacesContext.getCurrentInstance().getViewRoot()
				.setLocale(new Locale("en"));
		locale = new Locale("en");
		return null;
	}

	public String changeCN() {
		FacesContext.getCurrentInstance().getViewRoot()
				.setLocale(new Locale("zh_cn"));
		locale = new Locale("zh_cn");
		return null;
	}

	public String changeTW() {
		FacesContext.getCurrentInstance().getViewRoot()
				.setLocale(new Locale("zh_tw"));
		locale = new Locale("zh_tw");
		return null;
	}
}
